wctype.h
wctype.h provides a wide character version of the functions in ctype.h.
Wide character type determination functions
The following function determines the type of a wide character.
- iswalnum() tests whether a wide character is alphanumeric
- iswalpha() tests whether the wide character is alphabetic
- iswblank() tests whether this is a wide blank character
- iswcntrl() tests if this is a wide control character
- iswdigit() tests if this is a wide character that is a number
- iswgraph() tests if the wide character is a printable non-whitespace character
- iswlower() tests whether the wide character is lowercase
- iswprint() tests if the wide character is printable
- iswpunct() tests whether a wide character is punctuated
- iswspace() tests if a wide character is a space
- iswupper() tests if a wide character is uppercase
- iswxdigit() tests if a wide character is a hexadecimal digit
wctype(), iswctype()
iswctype()` is a generic version of the various wide character type determination functions in the previous section, and must be used in conjunction with
wctype()`.
int iswctype(wint_t wc, wctype_t desc);
iswctype()` accepts two arguments, the first being a wide character whose type needs to be determined, and the second being the wide character type description from the return value of
wctype()`.
If the wide character is of the specified type, iswctype()
returns a non-zero value, otherwise it returns zero.
wctype()
is used to get the type description of a certain kind of wide character.
wctype_t wctype(const char* property);
The argument to wctype()
is a given string with the following values available: alnum, alpha, blank, cntrl, digit, graph, lower, print, punct, space, upper, xdigit.
The return value of wctype()
is of type wctype_t, which is usually an integer. If the argument is an invalid value, 0
is returned.
if (iswctype(c, wctype("digit")))
// Equivalent to
if (iswdigit(c))
The above example is used to determine whether the wide character c
is a numeric value, and is equivalent to iswdigit()
.
The full type determination for iswctype()
is as follows.
iswctype(c, wctype("alnum")) // equivalent to iswalnum(c)
iswctype(c, wctype("alpha")) // equivalent to iswalpha(c)
iswctype(c, wctype("blank")) // equivalent to iswblank(c)
iswctype(c, wctype("cntrl")) // equivalent to iswcntrl(c)
iswctype(c, wctype("digit")) // equivalent to iswdigit(c)
iswctype(c, wctype("graph")) // equivalent to iswgraph(c)
iswctype(c, wctype("lower")) // equivalent to iswlower(c)
iswctype(c, wctype("print")) // equivalent to iswprint(c)
iswctype(c, wctype("punct")) // equivalent to iswpunct(c)
iswctype(c, wctype("space")) // equivalent to iswspace(c)
iswctype(c, wctype("upper")) // equivalent to iswupper(c)
iswctype(c, wctype("xdigit")) // equivalent to iswxdigit(c)
Case conversion functions
wctype.h provides the following case-sensitive conversion functions for wide characters.
- towlower() converts uppercase wide characters to lowercase
- towupper() converts lowercase wide characters to uppercase
- towctrans() generic function for wide character case conversion
- wctrans() helper function for case conversion, used in conjunction with towctrans()
See first the example usage of towlower()
and towupper()
.
towlower(L'B') // b
towupper(L'e') // E
The prototypes of towctrans()
and wctrans()
are as follows.
wint_t towctrans(wint_t wc, wctrans_t desc);
wctrans_t wctrans(const char* property);
Here are examples of their usage.
towctrans(c, wctrans("toupper")) // equivalent to towupper(c)
towctrans(c, wctrans("tolower")) // equivalent to towlower(c)